#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  01-UID-sysadm.sh
# Version	:  1.0
# Date		:  2020/05/28
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#                  Version 1.0, 2020/05/28
# Function	： 测试三权分立-用户标识
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="三权分立(sysadm) - 用户标识"

HeadFile_Source_LTFLIB="${LIB_SSHAUTO}"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	return ${TPASS}
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
	return ${TPASS}
}


## TODO : 测试用例
testcase_1(){
	# 临时用户
	local tmpuser_uid="ltfuidsysadm"
	# UID号
	local uid_1=""
	local uid_2=""

	# 如果存在用户则删除	
	SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no" &>/dev/null
	SshAuto_CmdLocalSys_LTFLIB "sudo useradd $tmpuser_uid" "no" "no"

	# 获取UID
	uid_1=$(id -u ${tmpuser_uid})
	echo "新建用户 ${tmpuser_uid} 的UID: $uid_1"

	SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no"
	SshAuto_CmdLocalSys_LTFLIB "sudo useradd $tmpuser_uid" "no" "no"
	# 获取UID
	uid_2=$(id -u ${tmpuser_uid})
	echo "删除后重建用户 ${tmpuser_uid} 的UID: $uid_2"

	SshAuto_CmdLocalSys_LTFLIB "sudo userdel -rf $tmpuser_uid" "no" "no"
	
	if [ "Z$uid_1" != "Z$uid_2" ];then
	# UID不一致
		OutputRet_LTFLIB ${TPASS}
		TestRetParse_LTFLIB "要求两次UID 不一致" "False"
	else
		OutputRet_LTFLIB ${TFAIL}
		TestRetParse_LTFLIB "要求两次UID 不一致" "False"
	fi
}

## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
	testcase_1

	return $TPASS
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
